package com.learn.springcloud.ribboncodingconfigconsumer;

import com.learn.springcloud.config.ConsumerRibbonClientConfiguration1;
import com.learn.springcloud.config.ConsumerRibbonClientConfiguration2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@ComponentScan(
    excludeFilters = @ComponentScan.Filter(
        type = FilterType.ANNOTATION,
        value = {
            com.learn.springcloud.ribboncodingconfigconsumer.annotation.ExcludeComponent.class
        }
    )
)
@RibbonClients(
        value = {
                @RibbonClient(name = "ribbon-coding-config-provider-group1", configuration = ConsumerRibbonClientConfiguration1.class),
                @RibbonClient(name = "ribbon-coding-config-provider-group2", configuration = ConsumerRibbonClientConfiguration2.class)
        }
)
public class RibbonCodingConfigConsumerApplication {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(RibbonCodingConfigConsumerApplication.class, args);
    }
}
